<template>
  <div class="app-container">
    <div style="color:#999;margin-bottom:10px;font-size:12px">仅当交易类型单选"红利（包括加币-计入红利）"、"加币-不计红利"、"减币时，可选择细分类型"</div>
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline">
      <el-form-item label="交易类型" prop="orderType" style="width:350px">
        <el-select
         @change="handlechange"
          :collapse-tags="true"
          v-model="formInline.orderType"  multiple placeholder="请选择交易类型" >
          <el-option
            v-for="item in consts.MEMBER_ORDER_TYPE_DETAIL"
            :label="item.title"
            :key="item.value"
            :value="item.value"
             v-if="item.value !== -1"
          ></el-option>
        </el-select>
      </el-form-item>

       <el-form-item label="细分类型" prop="subType"  >
        <el-select :disabled="subMenu.length<1"
          v-model="formInline.subType"
          :collapse-tags="true"
           width="100%" multiple placeholder="请选择细分类型">
          <el-option
            v-for="item in subMenu"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="状态" prop="status" >
        <el-select
          :collapse-tags="true"
          v-model="formInline.status" width="100%"  placeholder="请选择状态">
          <el-option
            v-for="item in statusList"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="查询时间" prop="time">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerDayStep"
          :default-time="['00:00:00', '23:59:59']"
          value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button v-if="roleCheck('export-user-info')" type="primary" size="mini" icon="el-icon-download" @click="_exportExcel">导出</el-button>
      <el-button @click="cancel('formInline')">重置</el-button>
    </el-form>
  </div>

</template>

<script>
import { form, pickerOption } from '@/build';

export default {
  name: 'form-filter',
  mixins: [form, pickerOption],
  data() {
    return {
      statusList: [
        { title: '全部', value: '' },
        { title: '处理中', value: 0 },
        { title: '失败', value: 2 },
        { title: '成功', value: 1 },
      ],
      type: null,
      subMenu: [],
      formInline: {
        orderType: [1, 2, 3, 4, 5, 6, 10, 11, 14],
        time: [moment().startOf('isoWeek').format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')],
        status: '', // 状态
        subType: [], // 细分类型

      },
    };
  },
  watch: {
    type(newVal) {
      this.formInline.childType = [];
    },
    formInline: {
      handler(newVal) {
        this.subMenu = [];
        this.type = undefined;
        if (newVal.orderType.length == 1) {
          this.type = newVal.orderType[0];
          if (this.type == 4) { // 红利（包括加币-计入红利）
            this.subMenu = consts.MEMBER_ORDER_TYPE_DETAIL[4].children;
          } else if (this.type == 14) { // 加币（不计红利）
            this.subMenu = consts.MEMBER_ORDER_TYPE_DETAIL[7].children;
          } else if (this.type == 10) { // 减币
            this.subMenu = consts.MEMBER_ORDER_TYPE_DETAIL[9].children;
          }
        } else {

        }
      },
      deep: true,
    },
  },

  methods: {
    handlechange() {
      this.formInline.subType = [];
    },
    _exportExcel() {
      this.$emit('on-export', this.formInline);
    },
    handleFilter() {
      if (this.formInline.orderType.length === 0) {
        this.$message({
          message: '请先选择交易类型',
          type: 'warning',
        });
        return;
      }
      this.$emit('on-filter', this.formInline);
    },
    cancel(formName) {
      this.resetForm(formName);
      this.handleFilter();
    },
  },

};
</script>

<style lang="scss" scoped>
/deep/ .el-select{width:260px}
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 80px;
      }
    }
  }

  .money-range {
    .el-input {
      width: 100px;
    }
  }

</style>
